from typing import List, Set, Tuple, Dict

Cluster = Set[str]
Arch = Dict[str, Cluster]


def get_module(arch: Arch, obj: str) -> str:
    for module, cluster in arch.items():
        if obj in cluster:
            return module
    return ""


def from_list(items: List[Tuple[str, str]]) -> Arch:
    a = dict()
    for module, obj in items:
        if module not in a:
            a[module] = set()
        a[module].add(obj)
    return a


def from_rsf(filename: str) -> Arch:
    a = dict()
    with open(filename, "r", encoding="utf-8") as f:
        for line in f.readlines():
            item = line.strip().split()
            if item:
                module, obj = item[1], item[2]
                if module not in a:
                    a[module] = set()
                a[module].add(obj)
                # print(module,'\t->\t',obj)
    return a
